<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        //父类
        function Person(name, age) {
            this.name = name
            this.age = age
        }
        Person.prototype.show = function () {
            console.log(this.name, this.age)
        }
        //寄生组合式继承
        //构造函数继承属性，
        function Student(name, age) {
            Person.call(this, name, age)
        }
        //原型链继承方法
        Student.prototype = Object.create(Person.prototype)
        //将创建的原型，赋值给子类
        Student.prototype.constructor = Student



        const s = new Student('why', 18)











        //Object.create测试
        //将一个对象作为原型。创建一个新的对象
        //参数1 ，源对象
        //参数2，可以用来覆盖源对象中的属性或者方法
        const food = {
            name: 'apple',
            eat() {
                console.log('吃苹果')
            }
        }

        const nFood = Object.create(food, {
            name: {
                value: 'orange'
            }
        })
    </script>
</body>

</html>